package exp02;

import java.util.Arrays;
import java.util.Scanner;

public class G {
	static class Person implements Comparable<Person>{
	
		@Override
		public String toString() {
			return this.name;
		}
		public Person(String name, int y, int m, int d) {
			super();
			this.name = name;
			this.y = y;
			this.m = m;
			this.d = d;
		}
		@Override
		public int compareTo(Person that) {
			if(this.y!=that.y)return this.y-that.y;
			if(this.m!=that.m)return this.m-that.m;
			return this.d-that.d;
		}
		
		
		String name;
		int y,m,d;
	}
public static void main(String[] args) {
	int n=cin.nextInt();
	Person [] persons=new Person[n];
	System.err.println(Arrays.toString(persons));
	for(int i=0;i<n;i++) {
		persons[i]=new Person(cin.next(),cin.nextInt(),cin.nextInt(),cin.nextInt());
	}
	Arrays.sort(persons);
	for(Person person:persons) {
		System.out.println(person);
	}
	
}
static Scanner cin=new Scanner(System.in);
}
